package test.clone;

import java.io.IOException;

import org.junit.Test;

public class CloneMain {

	/**
	 * @param args
	 * @throws CloneNotSupportedException
	 */
	// ShallowClone
	@Test
	public void testDeepClone1() throws CloneNotSupportedException {
		CloneClass c1 = new CloneClass();
		TypeClass ty = new TypeClass();
		ty.setStrType("before clone strType");
		ty.setTypeNumber(11);
		c1.setStr("before clone str");
		c1.setNumber(1);
		c1.setTypeClass(ty);
		System.out.println(c1);
		System.out.println("=====================");
		CloneClass c2 = c1.clone();
		c2.setNumber(2);
		c2.setStr("after clone str");
		c2.getTypeClass().setStrType("after clone strType");
		c2.getTypeClass().setTypeNumber(22);
		System.out.println(c1);
		System.out.println(c2);
	}

	@Test
	public void testDeepClone2() throws CloneNotSupportedException, IOException, ClassNotFoundException {
		DeepCloneClass c1 = new DeepCloneClass();
		DeepTypeClass ty = new DeepTypeClass();
		ty.setStrType("before clone strType");
		ty.setTypeNumber(11);
		c1.setStr("before clone str");
		c1.setNumber(1);
		c1.setTypeClass(ty);
		System.out.println(c1);
		System.out.println("=====================");
		DeepCloneClass c2 = c1.deepClone();
		c2.setNumber(2);
		c2.setStr("after clone str");
		c2.getTypeClass().setStrType("after clone strType");
		c2.getTypeClass().setTypeNumber(22);
		System.out.println(c1);
		System.out.println(c2);
	}
}
